import pandas as pd
from pyechart import options as opts
from pyecharts.charts import Scatter
df=pd.read_excel('某店铺销售数据.xlsx')
scatter=Scatter(init_opts=opts.InitOpts(page_title='气泡图'))
scatter.add_xaxis(xaxis_data=df['商品价格（元）'])
scatter.add_yaxis(series_name='',
                  y_axis=df[['销售额（元）','利润率（%）']].values.tolist(),
                  lable_opts=opts.LabelOpts(is_show=False)
)
scatter.set_global_opts(
    title_opts=opts.TitleOpts(
        title='某店铺商品价格与销售额,利润率相关性气泡图',
        pos_left='center'),
    xaxis_opts=opts.AxisOpts(name='商品价格（元）',
        name_location='center', name_gap=30),
    yaxis_opts=opts.AxisOpts(name='销售额（元）',
        name_location='center', name_gap=55),
    legend_opts=opts.LegendOpts(is_show=False),
    vidualmap_opts=opts.VisualMapOpts(type_='size', max=210,
        min_=40, range_size=[5,30], dimension=2, pos_top='55%',pos_right='right')
)
scatter.render('例5-3.html')